package com.example.demo.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j //打印日志
@ResponseBody
@ControllerAdvice
public class ErrorAdvice {
    //定义一个方法捕获所有的异常
    @ExceptionHandler(Exception.class)
    public Result errHandler(Exception e){
        log.error(e.toString());//打印异常信息
        return Result.fail(-1,"内部错误");
    }
}
